﻿using System.Windows;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;

namespace WinSPen.Objects
{
    /// <summary>
    /// Stroke에 포함되는 한 점을 나타내는 클래스
    /// </summary>
    public class WSPPoint
    {
        public WSPPoint(Layer layer, int strokeID)
        {
            this._createTime = DateTime.Now;
            this._parentStroke = FindParentStroke(layer, strokeID);
        }

        private Point _point;

        /// <summary>
        /// 이 WSPPoint의 위치
        /// </summary>
        public Point Point
        {
            get
            {
                if(this._point == null)
                {
                    this._point = new Point();
                }
                return this._point;
            }
        }

        private DateTime _createTime;

        /// <summary>
        /// 이 WSPPoint의 생성 시간
        /// </summary>
        public DateTime CreateTime
        {
            get
            {
                if (this._createTime == null)
                {
                    this._createTime = DateTime.Now;
                }
                return this._createTime;
            }
        }

        private WSPStroke _parentStroke;

        /// <summary>
        /// 이 WSPPoint를 가지고 있는 WSPStroke
        /// </summary>
        public WSPStroke ParentStroke
        {
            get
            {
                if (this._parentStroke == null)
                {
                    this._parentStroke = new WSPStroke(Layer.Local);
                }
                return this._parentStroke;
            }
        }

        /// <summary>
        /// 해당 objectID 를 가진 Stroke를 layer에서 탐색합니다.
        /// </summary>
        /// <param name="layer">탐색할 layer(Local, Network)</param>
        /// <param name="objectID">검색할 Object의 ID</param>
        /// <returns>탐색된 WSPStroke객체, 없을경우 null</returns>
        public WSPStroke FindParentStroke(Layer layer, int objectID)
        {
            WSPStroke wspStroke = null;

            if (layer == Layer.Local)
            {
                wspStroke = WSPLocalLayer.GetInstance().GetObjectByID(objectID) as WSPStroke;
            }
            else
            {
                wspStroke = WSPNetworkLayer.GetInstance().GetObjectByID(objectID) as WSPStroke;
            }

            return wspStroke;
        }
    }
}
